package simri.desktop.gui;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.rmi.RemoteException;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;

import webservice.LeituraSensor;
import webservice.Sensor;
import webservice.TipoSensor;
import webservice.UCManagerWebService;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class TesteBD extends javax.swing.JFrame {
	private JLabel jlTitulo;
	private JTextField jtTime;
	private JButton jbCancel;
	private JButton jbGravar;
	private JTextField jtData;
	private JTextField jtValor;
	private JTextField jtTipoSensor;
	private JTextField jtNomeSensor;
	private JLabel jlTempo;
	private JLabel jlData;
	private JLabel jlValor;
	private JLabel jlTipoSensor;
	private JLabel jlNomeSensor;

	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				TesteBD inst = new TesteBD();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public TesteBD() {
		super();
		initGUI();
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jlTitulo = new JLabel();
				getContentPane().add(jlTitulo);
				jlTitulo.setText("Sistema de Monitoramento Remoto - Teste Sensor");
				jlTitulo.setBounds(118, 23, 348, 16);
			}
			{
				jlNomeSensor = new JLabel();
				getContentPane().add(jlNomeSensor);
				jlNomeSensor.setText("Nome Sensor: ");
				jlNomeSensor.setBounds(23, 80, 113, 16);
			}
			{
				jlTipoSensor = new JLabel();
				getContentPane().add(jlTipoSensor);
				jlTipoSensor.setText("Tipo do Sensor: ");
				jlTipoSensor.setBounds(23, 131, 111, 16);
			}
			{
				jlValor = new JLabel();
				getContentPane().add(jlValor);
				jlValor.setText("Valor da Leitura: ");
				jlValor.setBounds(23, 180, 114, 16);
			}
			{
				jlData = new JLabel();
				getContentPane().add(jlData);
				jlData.setText("Data da Leitura (dd/mm/aa) :");
				jlData.setBounds(23, 232, 186, 16);
			}
			{
				jlTempo = new JLabel();
				getContentPane().add(jlTempo);
				jlTempo.setText("Horario da Leitura (hh:mm:ss) : ");
				jlTempo.setBounds(23, 283, 191, 16);
			}
			{
				jtNomeSensor = new JTextField();
				getContentPane().add(jtNomeSensor);
				jtNomeSensor.setBounds(118, 77, 354, 23);
			}
			{
				jtTipoSensor = new JTextField();
				getContentPane().add(jtTipoSensor);
				jtTipoSensor.setText("");
				jtTipoSensor.setBounds(120, 128, 352, 23);
			}
			{
				jtValor = new JTextField();
				getContentPane().add(jtValor);
				jtValor.setText("");
				jtValor.setBounds(123, 177, 136, 23);
			}
			{
				jtData = new JTextField();
				getContentPane().add(jtData);
				jtData.setBounds(189, 229, 120, 23);
			}
			{
				jtTime = new JTextField();
				getContentPane().add(jtTime);
				jtTime.setBounds(207, 280, 121, 23);
			}
			{
				jbGravar = new JButton();
				getContentPane().add(jbGravar);
				jbGravar.setText("Gravar");
				jbGravar.setBounds(457, 321, 81, 23);
				jbGravar.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jbGravar.actionPerformed, event="+evt);
						TipoSensor ts = new TipoSensor();
						LeituraSensor ls = new LeituraSensor();
						Sensor s = new Sensor();
						s.setNomeSensor(jtNomeSensor.getText());
						ts.setNomeTipo(jtTipoSensor.getText());
						ls.setValorLeitura(jtValor.getText());
						ls.getDataLeitura().setTime(new java.util.Date());
						s.setLtSensor(ls);
						s.setTipoSensor(ts);
						try {
							UCManagerWebService.getService().cadSensor(s);

							UCManagerWebService.getService().cadLeitura(ls);
						} catch (RemoteException e) {
							// TODO Auto-generated catch block
							e.printStackTrace();
						}
					}
				});
			}
			{
				jbCancel = new JButton();
				getContentPane().add(jbCancel);
				jbCancel.setText("Cancelar");
				jbCancel.setBounds(351, 321, 95, 23);
				jbCancel.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jbCancel.actionPerformed, event="+evt);
						//TODO add your code for jbCancel.actionPerformed
						dispose();
					}
				});
			}
			pack();
			setSize(600, 400);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}

}
